package cn.com.io.day20151210;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

/**
 * Created by Administrator on 2015/12/10.
 */
public class RedirectIn {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(System.getProperty("user.dir")+"\\src\\cn\\com\\io\\day20151210\\RedirectIn.java");
            System.setIn(fis);//将标准输入重定向到fis输入流
            Scanner scanner = new Scanner(System.in);//使用System.in创建Scanner对象，用于获取标准输入
            scanner.useDelimiter("\n");//只把回车作为分隔符
            while(scanner.hasNext()){
                //判断是否还有下一个输入项
                System.out.println("键盘输入的内容是："+ scanner.next());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally {
            if(fis !=null){
                fis.close();
            }
        }
    }
}
